package org.hbgl.geoentity.db.service;

import com.github.pagehelper.PageHelper;
import org.hbgl.geoentity.db.dao.GeCarouselMapper;
import org.hbgl.geoentity.db.dao.GeContentMapper;
import org.hbgl.geoentity.db.domain.GeCarousel;
import org.hbgl.geoentity.db.domain.GeCo;
import org.hbgl.geoentity.db.domain.GeContent;
import org.hbgl.geoentity.db.domain.SiteSetting;
import org.hbgl.geoentity.db.vo.CarouselVo;
import org.hbgl.geoentity.db.vo.CoVo;
import org.hbgl.geoentity.db.vo.ContentVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 代码功能：
 * 开发日期：2022/4/26
 * 作者：蒋海仑
 * 联系方式：
 * 版本更迭说明：
 * 版权信息：河北广联信息技术有限公司
 */
@Service
public class GeContentService {
    @Resource
    private GeContentMapper cententMapper;

    @Resource
    private GeCarouselMapper carouselMapper;

    public List<ContentVo> selectContentList(Integer columnId, String title, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return cententMapper.selectContentList(columnId, title);
    }

    public List<GeContent> findByTitleAndColumnId(Integer columnId, String title) {
        return cententMapper.findByTitleAndColumnId(columnId, title);
    }

    public int insertContent(GeContent content) {
        content.setAddTime(LocalDateTime.now());
        content.setEditTime(LocalDateTime.now());
        return cententMapper.insertContent(content);
    }

    public ContentVo findContentById(Integer id) {
        return cententMapper.findContentById(id);
    }

    public int deleteContentById(Integer id) {
        return cententMapper.deleteContentById(id);
    }

    public int updateContent(GeContent geContent) {
        geContent.setEditTime(LocalDateTime.now());
        return cententMapper.updateByExampleSelective(geContent);
    }

    public SiteSetting seeSiteSetting() {
        List<SiteSetting> siteSettings = cententMapper.seeSiteSetting();
        if(siteSettings != null && siteSettings.size()>0) {
            return siteSettings.get(0);
        }
        return null;
    }

    public int updateSiteSettingById(SiteSetting siteSetting) {
        siteSetting.setEditTime(LocalDateTime.now());
        return cententMapper.updateSiteSettingById(siteSetting);
    }

    public List<ContentVo> selectContentList(Integer columnId, String title, String startTime, String endTime, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return cententMapper.queryContentList(columnId, title, startTime, endTime);
    }

    public List<ContentVo> selectSiteContentList(Integer columnId, String title, String startTime, String endTime) {
        return cententMapper.querySiteContentList(columnId, title, startTime, endTime);
    }


    public List<CoVo> selectCoList(String title, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return cententMapper.selectCoList(title);
    }

    public List<CoVo> selectSiteCoList(String title) {
        return cententMapper.selectSiteCoList(title);
    }

    public List<GeCo> findCoByTitle(String title) {
        return cententMapper.findCoByTitle(title);
    }

    public int insertCo(GeCo co) {
        co.setAddTime(LocalDateTime.now());
        co.setEditTime(LocalDateTime.now());
        return cententMapper.insertCo(co);
    }

    public CoVo findCoById(Integer id) {
        return cententMapper.findCoById(id);
    }

    public int deleteCoById(Integer id) {
        return cententMapper.deleteCoById(id);
    }
    public int updateCo(GeCo geCo) {
        geCo.setEditTime(LocalDateTime.now());
        return cententMapper.updateCoByExampleSelective(geCo);
    }

    //region 轮播
    public List<CarouselVo> selectCarouselList(String title, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return cententMapper.selectCarouselList(title);
    }

    public List<CarouselVo> selectSiteCarouselList(String title) {
        return cententMapper.selectSiteCarouselList(title);
    }

    public List<GeCarousel> findCarouselByTitle(String title) {
        return cententMapper.findCarouselByTitle(title);
    }

    public int insertCarousel(GeCarousel co) {
        co.setAddTime(LocalDateTime.now());
        co.setEditTime(LocalDateTime.now());
        return cententMapper.insertCarousel(co);
    }

    public CarouselVo findCarouselById(Integer id) {
        return cententMapper.findCarouselById(id);
    }

    public int deleteCarouselById(Integer id) {
        return cententMapper.deleteCarouselById(id);
    }
    public int updateCarousel(GeCarousel geCo) {
        geCo.setEditTime(LocalDateTime.now());
        return cententMapper.updateCarouselByExampleSelective(geCo);
    }

    //endregion

}
